﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App.Validate
{
    public abstract class Validator
    {
        public string MessageTemplate { get; protected set; }
        public abstract ValidationError Validate(object objectToValidate);

        public Validator(string messageTemplate)
        {
            this.MessageTemplate = messageTemplate ?? string.Empty;
        }

        public virtual void FormatMessage(object objectToValidate)
        {
            this.MessageTemplate = this.MessageTemplate.Replace("{PropertyValue}", objectToValidate.ToString());
        }

        protected  ValidationError CreateValidationError(object objectToValidate)
        {
            Guard.ArgumentNotNull(objectToValidate, "objectToValidate");
            return new ValidationError(this.MessageTemplate, objectToValidate, this);
        }
    }
}